/// <reference types="vite/client" />

import { UserConfig, defineConfig, loadEnv } from 'vite'
// 自动导入模块
import AutoImport from 'unplugin-auto-import/vite'
// 自动导入组件
import Components from 'unplugin-vue-components/vite'
// Element Plus 插件
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 配置Vue插件
import vue from '@vitejs/plugin-vue'

import { resolve } from "path"

// https://vitejs.dev/config/
export default defineConfig((config: UserConfig) => {
  const { mode } = config
  const env = loadEnv(config.mode ?? '', `${process.cwd()}`)
  console.log(mode, env, __dirname)
  return {
    plugins: [
      vue(),
      AutoImport({
        // targets to transform
        include: [
          /\.[tj]sx?$/,
          /\.vue$/,
          /\.vue\?vue/,
          /\.md$/,
        ],
        // global imports to register
        imports: [
          // 插件预设支持导入的api
          'vue',
          'vue-router',
          'pinia'
          // 自定义导入的api
        ],
        resolvers: [
          ElementPlusResolver()
        ],
        dts: './auto-imports.d.ts',
      }),
      Components({
        resolvers: [
          ElementPlusResolver()
        ],
        dts: true,
      })
    ],
    base: './',
    resolve: {
      alias: {
        /** @ 符号指向 src 目录 */
        "@": resolve(__dirname, "./src")
      }
    },
    server: {
      port: 3000,
    },
  }
})
